package com.cryann.mqttserver.mqttProcess;

import io.netty.handler.codec.mqtt.MqttFixedHeader;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.Map;

/**
 * @author cRyann
 * @date 2018/12/14 0014 11:34
 * @description:
 */
@Component
@Slf4j
public class ProcessSelector {

    @Autowired
    Map<String, BasicProcess> processMap;

    @Autowired
    List<BasicProcess> basicProcessList;

    public BasicProcess getProves(MqttFixedHeader fixedHeader) {

        for (BasicProcess basicProcess : basicProcessList) {
            ProcessType processType = basicProcess.getClass().getAnnotation(ProcessType.class);
            if ( null != processType && fixedHeader.messageType() == processType.value() ) {
                log.debug("GET Process :[{}]", basicProcess.getClass().getSimpleName());
                return basicProcess;
            }
        }
        return null;
    }


}
